<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>MongoDB基础 | 北城韩雨</title><meta name="keywords" content="MongoDB"><meta name="author" content="北城韩雨"><meta name="copyright" content="北城韩雨"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="MongoDB">
<meta property="og:type" content="article">
<meta property="og:title" content="MongoDB基础">
<meta property="og:url" content="http://example.com/2019/03/27/MongoDB%E5%9F%BA%E7%A1%80/index.html">
<meta property="og:site_name" content="北城韩雨">
<meta property="og:description" content="MongoDB">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530644&t=10679b5732c52e39eeb588040240a790">
<meta property="article:published_time" content="2019-03-26T16:00:00.000Z">
<meta property="article:modified_time" content="2019-06-02T16:00:00.000Z">
<meta property="article:author" content="北城韩雨">
<meta property="article:tag" content="MongoDB">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530644&t=10679b5732c52e39eeb588040240a790"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2019/03/27/MongoDB%E5%9F%BA%E7%A1%80/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'MongoDB基础',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2019-06-03 00:00:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css"  media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/coin.css"  media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/liuxing.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css"  media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zhheo/JS-Heo@main/bb/showbb_in_index.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" media="print" onload="this.media='screen'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-butterfly-tag-plugins-plus/lib/tag_plugins.min.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/my.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">65</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">23</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">21</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/"><i class="fa-fw fas fa-home faa-tada"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/shuoshuo/"><i class="fa-fw fas fa-archive faa-tada"></i><span> 叨逼叨</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/tags/"><i class="fa-fw fas fa-tags faa-tada"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/categories/"><i class="fa-fw fas fa-folder-open faa-tada"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/link/"><i class="fa-fw fas fa-link faa-tada"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/comments/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-message"></use></svg><span> 留言板</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/about/"><i class="fa-fw fas fa-heart faa-tada"></i><span> 个人简介</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530644&amp;t=10679b5732c52e39eeb588040240a790')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">北城韩雨</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/"><i class="fa-fw fas fa-home faa-tada"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/shuoshuo/"><i class="fa-fw fas fa-archive faa-tada"></i><span> 叨逼叨</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/tags/"><i class="fa-fw fas fa-tags faa-tada"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/categories/"><i class="fa-fw fas fa-folder-open faa-tada"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/link/"><i class="fa-fw fas fa-link faa-tada"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/comments/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-message"></use></svg><span> 留言板</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/about/"><i class="fa-fw fas fa-heart faa-tada"></i><span> 个人简介</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">MongoDB基础</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-03-26T16:00:00.000Z" title="发表于 2019-03-27 00:00:00">2019-03-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2019-06-02T16:00:00.000Z" title="更新于 2019-06-03 00:00:00">2019-06-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">6.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>33分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="MongoDB基础"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="数据库之间的区别"><a href="#数据库之间的区别" class="headerlink" title="数据库之间的区别"></a>数据库之间的区别</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>数据库分为关系形数据库和非关系形数据库</span><br><span class="line"><span class="number">2.</span>非关系型数据就是减少了关系型数据库的一些功能 然后价格也十分的便宜</span><br><span class="line"><span class="number">3.</span>关系型数据库的数据结构 数据库 -&gt; 数据表 -&gt; 数据行(就是一行一行的数据)</span><br><span class="line"><span class="number">4.</span>非关系数据库结构 数据库 -&gt; 集合(理解为数据表) -&gt; 文件(理解为一行一行的数据)</span><br></pre></td></tr></table></figure>
<h1 id="基本操作"><a href="#基本操作" class="headerlink" title="基本操作"></a>基本操作</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>这里面可以写类似js的代码 如声明变量 或者 声明函数</span><br></pre></td></tr></table></figure>
<h1 id="基本命令"><a href="#基本命令" class="headerlink" title="基本命令"></a>基本命令</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">show dbs 查看链接中的所有数据库 如果库没有集合 就不会显示</span><br><span class="line">use 数据库名称 使用数据库 进入数据库 如果当前没有这个库 使用这个命令就会新建</span><br><span class="line">show collections 查看当前数据库中的集合</span><br><span class="line">db 查看当前在哪个数据库</span><br><span class="line">db.集合名称 在数据库新建一个集合</span><br><span class="line"><span class="comment">//下面我们一user集合名称举例</span></span><br><span class="line">db.user.insert(&#123;<span class="string">&quot;name&quot;</span>:<span class="string">&quot;wangzheng&quot;</span>&#125;)  <span class="comment">//在user的集合里插入一个数据文件</span></span><br><span class="line">db.user.find()  <span class="comment">//显示user下面的所有文件</span></span><br><span class="line">db.user.findOne() <span class="comment">//显示当前集合的第一个文件 方法遵循小驼峰命名</span></span><br><span class="line">db.user.update(&#123;<span class="string">&quot;name&quot;</span>:<span class="string">&quot;wangzheng&quot;</span>&#125;,&#123;<span class="string">&quot;name&quot;</span>:<span class="string">&quot;newwangzheng&quot;</span>&#125;) <span class="comment">//修改第一个是你要修改的 第二个参数是你要改成的</span></span><br><span class="line">db.user.remove(&#123;<span class="string">&quot;name&quot;</span>:<span class="string">&quot;newwangzheng&quot;</span>&#125;) <span class="comment">//删除文件</span></span><br><span class="line">db.user.drop() <span class="comment">//删除集合</span></span><br><span class="line">db.dropDatabase() <span class="comment">//删除库 必须在当前库下才可</span></span><br></pre></td></tr></table></figure>
<h1 id="用js文件来写MongoDB"><a href="#用js文件来写MongoDB" class="headerlink" title="用js文件来写MongoDB"></a>用js文件来写MongoDB</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>新建一个js文件 然后里面写json字符串 </span><br><span class="line"><span class="number">2.</span>运行命令行 使用mongo 要执行的js文件 即可</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; connect &#125; <span class="keyword">from</span> <span class="string">&quot;http2&quot;</span></span><br><span class="line"><span class="keyword">var</span> username = <span class="string">&#x27;wangzheng&#x27;</span></span><br><span class="line"><span class="keyword">var</span> time = <span class="built_in">Date</span>.parse(<span class="keyword">new</span> <span class="built_in">Date</span>())</span><br><span class="line"><span class="keyword">var</span> jsonString = &#123;<span class="string">&quot;name&quot;</span>:usernamem,<span class="string">&quot;time&quot;</span>:time&#125;</span><br><span class="line"><span class="comment">//链接一个数据库 如果没有则会自动创建</span></span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;log&#x27;</span>)</span><br><span class="line">db.login.insert(jsonString)</span><br><span class="line">print(<span class="string">&#x27;[demo]:log print success&#x27;</span>)</span><br><span class="line"><span class="comment">//当前目录下 mongo 执行文件即可</span></span><br></pre></td></tr></table></figure>
<h1 id="批量插入"><a href="#批量插入" class="headerlink" title="批量插入"></a>批量插入</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//使用插入数据的方式即可 ID自己写入</span></span><br><span class="line">&gt; db.more.insert([&#123;<span class="string">&quot;_id&quot;</span>:<span class="number">1</span>&#125;,&#123;<span class="string">&quot;_id&quot;</span>:<span class="number">2</span>&#125;,&#123;<span class="string">&quot;_id&quot;</span>:<span class="number">3</span>&#125;])</span><br><span class="line">BulkWriteResult(&#123;</span><br><span class="line">        <span class="string">&quot;writeErrors&quot;</span> : [ ],</span><br><span class="line">        <span class="string">&quot;writeConcernErrors&quot;</span> : [ ],</span><br><span class="line">        <span class="string">&quot;nInserted&quot;</span> : <span class="number">3</span>, <span class="comment">//显示插入三条</span></span><br><span class="line">        <span class="string">&quot;nUpserted&quot;</span> : <span class="number">0</span>,</span><br><span class="line">        <span class="string">&quot;nMatched&quot;</span> : <span class="number">0</span>,</span><br><span class="line">        <span class="string">&quot;nModified&quot;</span> : <span class="number">0</span>,</span><br><span class="line">        <span class="string">&quot;nRemoved&quot;</span> : <span class="number">0</span>,</span><br><span class="line">        <span class="string">&quot;upserted&quot;</span> : [ ]</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//插入数组 可以提升性能 test.js文件</span></span><br><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> tempArray = []</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">0</span> ; i &lt; <span class="number">1000</span>; i++)&#123;</span><br><span class="line">    tempArray.push(&#123;<span class="attr">num</span>:i&#125;)</span><br><span class="line">&#125;</span><br><span class="line">db.plcrcollection.insert(tempArray)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br><span class="line"><span class="comment">//然后执行mongo test.js 首先记得开启服务</span></span><br></pre></td></tr></table></figure>
<h1 id="修改"><a href="#修改" class="headerlink" title="修改"></a>修改</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//首先我们批量插入 修改的时候要记得整个对象一起修改</span></span><br><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"></span><br><span class="line">db.plcrcollection.insert(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,tempArray)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br><span class="line"><span class="comment">//修改</span></span><br><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    <span class="comment">//改成女</span></span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//然后查找之后 在变成我们修改之后的对象</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,three)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="错误的修改"><a href="#错误的修改" class="headerlink" title="错误的修改"></a>错误的修改</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    <span class="comment">//改成男</span></span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//这是错误的修改 这样修改完毕之后 这个three对象里就只有一个sex男了</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">sex</span>:<span class="string">&#x27;男&#x27;</span>&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="set修饰符"><a href="#set修饰符" class="headerlink" title="$set修饰符"></a>$set修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>上面是整个的修改 如果修改单项我们可以用$set修改器</span><br><span class="line"><span class="number">2.</span>也可以用来增加某一项数据</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//这样就可以用$set这种形式去修改了</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$set</span>:&#123;<span class="attr">age</span>:<span class="number">28</span>&#125;&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//如果是多层签到的数据 就和js语法一样 可以用点的形式 但是要加引号</span></span><br><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//以上都是嵌套的数据</span></span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//这里我们就可以通过点的形式 但是要加引号 去修改该你要改变的值</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$set</span>:&#123;<span class="string">&quot;skill.one&quot;</span>:<span class="string">&#x27;css&#x27;</span>&#125;&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="unset修饰符"><a href="#unset修饰符" class="headerlink" title="$unset修饰符"></a>$unset修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>$unset主要是用来删除数据中的</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">// db.plcrcollection.insert(tempArray)</span></span><br><span class="line"><span class="comment">//这样就吧skill.one删除了</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$unset</span>:&#123;<span class="string">&quot;skill.one&quot;</span>:<span class="string">&#x27;css&#x27;</span>&#125;&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="inc修饰符"><a href="#inc修饰符" class="headerlink" title="$inc修饰符"></a>$inc修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>可以对数据进行计算 和 操作</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//此处使用$inc就把年龄-2了</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$inc</span>:&#123;<span class="attr">age</span>:-<span class="number">2</span>&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="multi"><a href="#multi" class="headerlink" title="multi"></a>multi</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>当我们需要给所有的数据增加一个新的字段的时候 我们要用$set</span><br><span class="line"><span class="number">2.</span>这个时候我们只会给第一行数据增加了这个新的数据</span><br><span class="line"><span class="number">3.</span>所以我们要用multi这个配置 当他为<span class="literal">true</span>的时候 就会一行行的查找</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//没有multi</span></span><br><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//当没有multi的时候 他只会为第一个数据添加这个like的字段</span></span><br><span class="line">db.plcrcollection.update(&#123;&#125;,&#123;<span class="attr">$set</span>:&#123;<span class="attr">like</span>:<span class="string">&#x27;women&#x27;</span>&#125;&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//multi为true</span></span><br><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//这样就给我们上面所有的数据都添加了like字段</span></span><br><span class="line">db.plcrcollection.update(&#123;&#125;,&#123;<span class="attr">$set</span>:&#123;<span class="attr">like</span>:<span class="string">&#x27;women&#x27;</span>&#125;&#125;,&#123;<span class="attr">multi</span>:<span class="literal">true</span>&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="upset"><a href="#upset" class="headerlink" title="upset"></a>upset</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>用于往现有的数据里插入一条新的数据</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//此刻我们上面的数据里并没有name:赵六这个数据 所以我们开启了upsert选项之后 就会自动添加到我们的数据里面去</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;赵六&#x27;</span>&#125;,&#123;<span class="attr">$set</span>:&#123;<span class="attr">like</span>:<span class="string">&#x27;women&#x27;</span>&#125;&#125;,&#123;<span class="attr">upsert</span>:<span class="literal">true</span>&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="push修饰符"><a href="#push修饰符" class="headerlink" title="$push修饰符"></a>$push修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>在现有的数据上 插入新的key</span><br><span class="line"><span class="number">2.</span>比如我们的一行数据 其中有个字段是个数组 你想向里面插入新的数据 就可以用</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    arr:[]</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">// db.plcrcollection.insert(tempArray)</span></span><br><span class="line"><span class="comment">//向arr这个数据行中 插入了元素</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$push</span>:&#123;<span class="attr">arr</span>:<span class="string">&#x27;数组1&#x27;</span>&#125;&#125;)</span><br><span class="line"><span class="comment">//对象也是使用的 向skill对象里增加了一个新的字段叫two 值是css 但是类型是数组</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$push</span>:&#123;<span class="string">&#x27;skill.two&#x27;</span>:<span class="string">&#x27;css&#x27;</span>&#125;&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="ne修饰符"><a href="#ne修饰符" class="headerlink" title="$ne修饰符"></a>$ne修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>去查找某一下的数据里的某个值 如果查到了就不添加值 如果查不到就添加新的值</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    arr:[</span><br><span class="line">        <span class="string">&#x27;数组1&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组2&#x27;</span></span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//我们去查找一下name:王五里面的arr字段里的数组3 如果能找到我们就不push数组4 如果找不到就push数组4</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>,<span class="attr">arr</span>:&#123;<span class="attr">$ne</span>:<span class="string">&#x27;数组3&#x27;</span>&#125;&#125;,&#123;<span class="attr">$push</span>:&#123;<span class="attr">arr</span>:<span class="string">&#x27;数组4&#x27;</span>&#125;&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="addToSet修饰符"><a href="#addToSet修饰符" class="headerlink" title="$addToSet修饰符"></a>$addToSet修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ne的升级版 和上面意思一样</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    arr:[</span><br><span class="line">        <span class="string">&#x27;数组1&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组2&#x27;</span></span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//我去找name:&#x27;王五&#x27;的数据 找到他下面的arr看有没有数组五没有就添加</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$addToSet</span>:&#123;<span class="attr">arr</span>:<span class="string">&#x27;数组五&#x27;</span>&#125;&#125;)</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="each"><a href="#each" class="headerlink" title="$each"></a>$each</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>如果我需要往一个数组里插入多个字段 就需要用到$each</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    arr:[</span><br><span class="line">        <span class="string">&#x27;数组1&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组2&#x27;</span></span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="keyword">var</span> newArr = [<span class="string">&#x27;数组七&#x27;</span>,<span class="string">&#x27;数组8&#x27;</span>,<span class="string">&#x27;数组9&#x27;</span>]</span><br><span class="line"><span class="comment">//我先去看看 你有没有这些数据 如果没有我在添加 用$echa一次性添加</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$addToSet</span>:&#123;<span class="attr">arr</span>:&#123;<span class="attr">$each</span>:newArr&#125;&#125;&#125;)</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="pop"><a href="#pop" class="headerlink" title="$pop"></a>$pop</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>数组的删除修饰符 有两个参数 如果是<span class="number">1</span>从数组的末端开始删除 -<span class="number">1</span>从数组的开始进行删除</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    arr:[</span><br><span class="line">        <span class="string">&#x27;数组1&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组2&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组七&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组8&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组9&#x27;</span></span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//pop为1的时候从数组的末端开始删除了 如果参数为-1就从数组的开始删除了</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$pop</span>:&#123;<span class="attr">arr</span>:<span class="number">1</span>&#125;&#125;)</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="数组的定位修改"><a href="#数组的定位修改" class="headerlink" title="数组的定位修改"></a>数组的定位修改</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>主要是是用$set 然后选择数组的对应的索引进行修改</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    arr:[</span><br><span class="line">        <span class="string">&#x27;数组1&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组2&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组七&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组8&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组9&#x27;</span></span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">//这样就是把arr的数据的索引为第一位的数据修改了</span></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$set</span>:&#123;<span class="string">&#x27;arr.1&#x27;</span>:<span class="string">&#x27;我是被修改的&#x27;</span>&#125;&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">print(<span class="string">&#x27;dmoe run time is&#x27;</span>+ running +<span class="string">&#x27;ms&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="应答式操作"><a href="#应答式操作" class="headerlink" title="应答式操作"></a>应答式操作</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>我们刚刚上面的操作都是非应答式的  是没有返回值的 </span><br><span class="line"><span class="number">2.</span>所以我们现在要用有返回值的的操作 db.runCommand(&#123;<span class="attr">getLastError</span>:<span class="number">1</span>&#125;)</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> start = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="keyword">var</span> one = &#123;</span><br><span class="line">    name:<span class="string">&#x27;张三&#x27;</span>,</span><br><span class="line">    age:<span class="number">28</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ppt&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> two = &#123;</span><br><span class="line">    name:<span class="string">&#x27;李四&#x27;</span>,</span><br><span class="line">    age:<span class="number">16</span>,</span><br><span class="line">    sex:<span class="string">&#x27;男&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;ps&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> three = &#123;</span><br><span class="line">    name:<span class="string">&#x27;王五&#x27;</span>,</span><br><span class="line">    age:<span class="number">26</span>,</span><br><span class="line">    sex:<span class="string">&#x27;女&#x27;</span>,</span><br><span class="line">    skill:&#123;</span><br><span class="line">        one:<span class="string">&#x27;html&#x27;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    arr:[</span><br><span class="line">        <span class="string">&#x27;数组1&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组2&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组七&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组8&#x27;</span>,</span><br><span class="line">        <span class="string">&#x27;数组9&#x27;</span></span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> tempArray = [one,two,three]</span><br><span class="line"><span class="comment">// db.plcrcollection.insert(tempArray)</span></span><br><span class="line"><span class="comment">// db.plcrcollection.update(&#123;name:&#x27;王五&#x27;&#125;,&#123;$push:&#123;arr:&#x27;数组1&#x27;&#125;&#125;)</span></span><br><span class="line"><span class="keyword">var</span> newArr = [<span class="string">&#x27;数组七&#x27;</span>,<span class="string">&#x27;数组8&#x27;</span>,<span class="string">&#x27;数组9&#x27;</span>]</span><br><span class="line"><span class="comment">// db.plcrcollection.update(&#123;name:&#x27;王五&#x27;&#125;,&#123;$addToSet:&#123;arr:&#123;$each:newArr&#125;&#125;&#125;)</span></span><br><span class="line"></span><br><span class="line">db.plcrcollection.update(&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,&#123;<span class="attr">$set</span>:&#123;<span class="string">&#x27;arr.3&#x27;</span>:<span class="string">&#x27;我是被修改的&#x27;</span>&#125;&#125;)</span><br><span class="line"><span class="comment">//这里就是有了返回值</span></span><br><span class="line"><span class="keyword">const</span> res = db.runCommand(&#123;<span class="attr">getLastError</span>:<span class="number">1</span>&#125;)</span><br><span class="line"><span class="keyword">var</span> end = (<span class="keyword">new</span> <span class="built_in">Date</span>()).getTime()</span><br><span class="line"><span class="keyword">var</span> running = end - start</span><br><span class="line">printjson(res)</span><br><span class="line"><span class="comment">//打印出来的内容</span></span><br><span class="line">&#123;</span><br><span class="line">        <span class="string">&quot;connectionId&quot;</span> : <span class="number">17</span>,</span><br><span class="line">         <span class="comment">//这里就是修改成功了   </span></span><br><span class="line">        <span class="string">&quot;updatedExisting&quot;</span> : <span class="literal">true</span>,</span><br><span class="line">        <span class="string">&quot;n&quot;</span> : <span class="number">1</span>,</span><br><span class="line">        <span class="string">&quot;syncMillis&quot;</span> : <span class="number">0</span>,</span><br><span class="line">        <span class="string">&quot;writtenTo&quot;</span> : <span class="literal">null</span>,</span><br><span class="line">        <span class="string">&quot;err&quot;</span> : <span class="literal">null</span>,</span><br><span class="line">        <span class="string">&quot;ok&quot;</span> : <span class="number">1</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//也可以用来看看数据库链接成功了没有</span></span><br><span class="line">db.runCommand(&#123;<span class="attr">ping</span>:<span class="number">1</span>&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="findAndModify"><a href="#findAndModify" class="headerlink" title="findAndModify"></a>findAndModify</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>我们可以理解为是写配置的方式去写操作数据库</span><br><span class="line">query参数 用于 需要查询的条件</span><br><span class="line">sort 进行排序</span><br><span class="line">remove 查找到相同的条件之后删除</span><br><span class="line"><span class="keyword">new</span> 布尔什  返回更新之前的文档 或者更新之后的</span><br><span class="line">fields 需要返回的字段</span><br><span class="line">upsert 同上面一样 鹤remove只能存在一个</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> db = connect(<span class="string">&#x27;plcr&#x27;</span>)</span><br><span class="line"><span class="comment">//这样就是用写配置的方法 去写查询修改</span></span><br><span class="line"><span class="keyword">const</span> findAndModify = &#123;</span><br><span class="line">    findAndModify:<span class="string">&#x27;plcrcollection&#x27;</span>, <span class="comment">//你要修改的是哪个集合</span></span><br><span class="line">    query:&#123;<span class="attr">name</span>:<span class="string">&#x27;王五&#x27;</span>&#125;,</span><br><span class="line">    <span class="keyword">new</span>: <span class="literal">true</span>,</span><br><span class="line">    update:&#123;<span class="attr">$set</span>:&#123;<span class="string">&#x27;arr.2&#x27;</span>:<span class="string">&#x27;我被修改了&#x27;</span>&#125;&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//然后用runCommand去运行这个配置 返回结果</span></span><br><span class="line"><span class="keyword">const</span> res = db.runCommand(findAndModify)</span><br><span class="line">printjson(res,<span class="string">&#x27;---&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h1 id="查询"><a href="#查询" class="headerlink" title="查询"></a>查询</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>首先我们来熟悉几个比较的操作符</span><br><span class="line">$lt 小于 全称 less-than</span><br><span class="line">$lte 小于等于 全称 less-than-equal</span><br><span class="line">$gt 大于 全称 greater-than</span><br><span class="line">$gte 大于等于 全称 greater-than-equal</span><br><span class="line">$ne 不等于 全称 not-equal</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">数据库数组</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a8f&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;JSPang&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">33</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PHP&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a90&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;ShengLei&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">31</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;JAVA后端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;J2EE&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PPT&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a91&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;MinJie&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">18</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PPT&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a92&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;XiaoWang&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">25</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PPT&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a93&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;LiangPeng&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">28</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a94&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;HouFei&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">25</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a95&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;LiuYan&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">35</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;美工&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;CAD&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a96&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;DingLu&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">20</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;美工&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;CAD&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a97&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;JiaPeng&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">29</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PHP&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a98&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;LiJia&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">26</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PHP&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//我们去根据条件查找以上的数据 下面是查找的条件</span></span><br><span class="line">db.workmate.find(&#123;<span class="string">&#x27;skill.skillOne&#x27;</span>:<span class="string">&#x27;HTML+CSS&#x27;</span>,<span class="attr">name</span>:<span class="string">&#x27;HouFei&#x27;</span>&#125;)</span><br><span class="line"><span class="comment">//查找年龄 大于30 小于15   为true只为返回的字段</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">age</span>:&#123;<span class="attr">$lt</span>:<span class="number">30</span>,<span class="attr">$gt</span>:<span class="number">10</span>&#125;&#125;,&#123;<span class="attr">name</span>:<span class="literal">true</span>,<span class="attr">_id</span>:<span class="literal">true</span>,<span class="attr">sex</span>:<span class="literal">true</span>&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="多条件查询"><a href="#多条件查询" class="headerlink" title="多条件查询"></a>多条件查询</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>$in 修饰符 可以查询指定值的多条数据</span><br><span class="line"><span class="number">2.</span>$nin 修饰符 同上面相反</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//查询年龄为25 和 35的数据 </span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">age</span>:&#123;<span class="attr">$in</span>:[<span class="number">25</span>,<span class="number">35</span>]&#125;&#125;,&#123;<span class="attr">name</span>:<span class="literal">true</span>,<span class="attr">skill</span>:<span class="literal">true</span>&#125;)</span><br><span class="line"><span class="comment">//查询年龄不是25和35的数据</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">age</span>:&#123;<span class="attr">$nin</span>:[<span class="number">25</span>,<span class="number">35</span>]&#125;&#125;,&#123;<span class="attr">name</span>:<span class="literal">true</span>,<span class="attr">skill</span>:<span class="literal">true</span>&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="or-修饰符"><a href="#or-修饰符" class="headerlink" title="$or 修饰符"></a>$or 修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>满足我们的一个查询条件即可</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//查询要不年龄大于30 要不 就会PHP</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">$or</span>:[&#123;<span class="attr">age</span>:&#123;<span class="attr">$gte</span>:<span class="number">30</span>&#125;&#125;,&#123;<span class="string">&#x27;skill.skillThree&#x27;</span>:<span class="string">&#x27;PHP&#x27;</span>&#125;]&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="and修饰符"><a href="#and修饰符" class="headerlink" title="$and修饰符"></a>$and修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>同上面相反</span><br><span class="line"><span class="number">2.</span>并且的关系</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//查询年龄大于30岁并且会PHP的数据</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">$and</span>:[&#123;<span class="attr">age</span>:&#123;<span class="attr">$gte</span>:<span class="number">30</span>&#125;&#125;,&#123;<span class="string">&#x27;skill.skillThree&#x27;</span>:<span class="string">&#x27;PHP&#x27;</span>&#125;]&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="not-修饰符"><a href="#not-修饰符" class="headerlink" title="$not 修饰符"></a>$not 修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>查找查询条件之外的数据</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//查找年龄大于20 小于30 之外的数据</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">age</span>:&#123;<span class="attr">$not</span>:&#123;<span class="attr">$lte</span>:<span class="number">30</span>,<span class="attr">$gte</span>:<span class="number">20</span>&#125;&#125;&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="数据的数组操作"><a href="#数据的数组操作" class="headerlink" title="数据的数组操作"></a>数据的数组操作</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//新的数据 里面增加了数据</span></span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a8f&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;JSPang&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">33</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PHP&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a90&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;ShengLei&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">31</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;JAVA后端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;J2EE&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PPT&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a91&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;MinJie&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">18</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PPT&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea6d19d2f016fa8aca30a95&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;LiuYan&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">35</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;美工&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;CAD&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-27T12:35:41.746Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ ] &#125;</span><br><span class="line">&gt; db.workmate.drop()</span><br><span class="line"><span class="literal">true</span></span><br><span class="line">&gt; db.workmate.find()</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff74&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;JSPang&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">33</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PHP&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;看电影&quot;</span>, <span class="string">&quot;看书&quot;</span>, <span class="string">&quot;吃美食&quot;</span>, <span class="string">&quot;钓鱼&quot;</span>, <span class="string">&quot;旅游&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff75&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;ShengLei&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">31</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;JAVA后端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;J2EE&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PPT&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;篮球&quot;</span>, <span class="string">&quot;看电影&quot;</span>, <span class="string">&quot;做饭&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff76&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;MinJie&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">18</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PPT&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;做饭&quot;</span>, <span class="string">&quot;画画&quot;</span>, <span class="string">&quot;看电影&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff77&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;XiaoWang&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">25</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;UI&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PPT&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;写代码&quot;</span>, <span class="string">&quot;篮球&quot;</span>, <span class="string">&quot;画画&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff78&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;LiangPeng&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">28</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;玩游戏&quot;</span>, <span class="string">&quot;写代码&quot;</span>, <span class="string">&quot;做饭&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff79&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;HouFei&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">25</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;化妆&quot;</span>, <span class="string">&quot;读书&quot;</span>, <span class="string">&quot;做饭&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff7a&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;LiuYan&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">35</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;美工&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;CAD&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;画画&quot;</span>, <span class="string">&quot;聚会&quot;</span>, <span class="string">&quot;看电影&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff7b&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;DingLu&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">20</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;美工&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;PhotoShop&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;CAD&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;美食&quot;</span>, <span class="string">&quot;看电影&quot;</span>, <span class="string">&quot;做饭&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff7c&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;JiaPeng&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">29</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">1</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PHP&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;写代码&quot;</span>, <span class="string">&quot;篮球&quot;</span>, <span class="string">&quot;游泳&quot;</span> ] &#125;</span><br><span class="line">&#123; <span class="string">&quot;_id&quot;</span> : ObjectId(<span class="string">&quot;5ea82a08ccd68891a847ff7d&quot;</span>), <span class="string">&quot;name&quot;</span> : <span class="string">&quot;LiJia&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">26</span>, <span class="string">&quot;sex&quot;</span> : <span class="number">0</span>, <span class="string">&quot;job&quot;</span> : <span class="string">&quot;前端&quot;</span>, <span class="string">&quot;skill&quot;</span> : &#123; <span class="string">&quot;skillOne&quot;</span> : <span class="string">&quot;HTML+CSS&quot;</span>, <span class="string">&quot;skillTwo&quot;</span> : <span class="string">&quot;JavaScript&quot;</span>, <span class="string">&quot;skillThree&quot;</span> : <span class="string">&quot;PHP&quot;</span> &#125;, <span class="string">&quot;regeditTime&quot;</span> : ISODate(<span class="string">&quot;2020-04-28T13:05:12.460Z&quot;</span>), <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;玩游戏&quot;</span>, <span class="string">&quot;美食&quot;</span>, <span class="string">&quot;篮球&quot;</span> ] &#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>数据的查询 必须是完全比配 比如我们上面的每一项数据的interest 是个数据 我们在查询的时候 必须都要写全才会查询</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//错误的示范 这样写是完全匹配了</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">interest</span>:[<span class="string">&quot;玩游戏&quot;</span>, <span class="string">&quot;美食&quot;</span>, <span class="string">&quot;篮球&quot;</span> ]&#125;)</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//我们要查询数组里 会玩游戏的 数据 就可以不用加数组括号 这样就会把数组里含有玩游戏的人数据都查询出来了</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">interest</span>:<span class="string">&quot;玩游戏&quot;</span>&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="all-数组修饰符"><a href="#all-数组修饰符" class="headerlink" title="$all 数组修饰符"></a>$all 数组修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>查询数组数据都满足条件的数据</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//查询数组 数据 必须有 看书 看电影</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">interest</span>:&#123;<span class="attr">$all</span>:[<span class="string">&#x27;看书&#x27;</span>,<span class="string">&#x27;看电影&#x27;</span>]&#125;&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="in-数组修饰符"><a href="#in-数组修饰符" class="headerlink" title="$in 数组修饰符"></a>$in 数组修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>查询数组数据中满足我们查询条件的其中一个即可</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//查询出来的数据 他的interest数组中 要不就有看书 要不就有看电影</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">interest</span>:&#123;<span class="attr">$in</span>:[<span class="string">&#x27;看书&#x27;</span>,<span class="string">&#x27;看电影&#x27;</span>]&#125;&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="size-数组修饰符"><a href="#size-数组修饰符" class="headerlink" title="$size 数组修饰符"></a>$size 数组修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>查询数据的数组中 长度为多少的数据</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//查出来的数据就是 interest这个字段的数组 长度为5的数据</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">interest</span>:&#123;<span class="attr">$size</span>:<span class="number">5</span>&#125;&#125;)</span><br></pre></td></tr></table></figure>
<h1 id="slice数组修饰符"><a href="#slice数组修饰符" class="headerlink" title="$slice数组修饰符"></a>$slice数组修饰符</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>用于查询出来的数组数据 只显示几位</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//我们取查询interest这个字段的数组长度为5的数据 然后显示给我们的只有数组的第一位</span></span><br><span class="line">db.workmate.find(&#123;<span class="attr">interest</span>:&#123;<span class="attr">$size</span>:<span class="number">5</span>&#125;&#125;,&#123;<span class="attr">name</span>:<span class="literal">true</span>,<span class="attr">age</span>:<span class="literal">true</span>,<span class="attr">_id</span>:<span class="literal">false</span>,<span class="attr">interest</span>:&#123;<span class="attr">$slice</span>:<span class="number">1</span>&#125;&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">//查询结果如下</span></span><br><span class="line">&#123; <span class="string">&quot;name&quot;</span> : <span class="string">&quot;JSPang&quot;</span>, <span class="string">&quot;age&quot;</span> : <span class="number">33</span>, <span class="string">&quot;interest&quot;</span> : [ <span class="string">&quot;看电影&quot;</span> ] &#125;</span><br></pre></td></tr></table></figure>
<h1 id="在js文件里写查询"><a href="#在js文件里写查询" class="headerlink" title="在js文件里写查询"></a>在js文件里写查询</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>还是用打印的形式 只不过这里用了游标</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> db=connect(<span class="string">&#x27;company&#x27;</span>);</span><br><span class="line"><span class="keyword">const</span> res = db.workmate.find() <span class="comment">//这是查询如果来的结果</span></span><br><span class="line"><span class="comment">//如果有下一条</span></span><br><span class="line"><span class="keyword">while</span>(res.hasNext())&#123;</span><br><span class="line">    <span class="comment">//我们就打印</span></span><br><span class="line">    printjson(res.next());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//也可以用mongodb自带的forEach 去打印</span></span><br><span class="line"><span class="keyword">var</span> db=connect(<span class="string">&#x27;company&#x27;</span>);</span><br><span class="line"><span class="keyword">const</span> res = db.workmate.find()</span><br><span class="line">res.forEach(<span class="function"><span class="params">item</span> =&gt;</span> &#123;</span><br><span class="line">    printjson(item)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">//以上就把所有查询的数据都打印出来了</span></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__title"><span class="post-copyright-info"><h>MongoDB基础</h></span></div><div class="post-copyright__type"><span class="post-copyright-info"><a href="http://example.com/2019/03/27/MongoDB%E5%9F%BA%E7%A1%80/">http://example.com/2019/03/27/MongoDB%E5%9F%BA%E7%A1%80/</a></span></div><div class="post-copyright-m"><div class="post-copyright-m-info"><div class="post-copyright-a"><h>作者</h><div class="post-copyright-cc-info"><h>北城韩雨</h></div></div><div class="post-copyright-c"><h>发布于</h><div class="post-copyright-cc-info"><h>2019-03-27</h></div></div><div class="post-copyright-u"><h>更新于</h><div class="post-copyright-cc-info"><h>2019-06-03</h></div></div><div class="post-copyright-c"><h>许可协议</h><div class="post-copyright-cc-info"><a class="icon" rel="noopener" target="_blank" title="Creative Commons" href="https://creativecommons.org/"><i class="fab fa-creative-commons"></i></a><a rel="noopener" target="_blank" title="CC BY-NC-SA 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a></div></div></div></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/MongoDB/">MongoDB</a></div><div class="post_share"></div></div><link rel="stylesheet" href="/" media="defer" onload="this.media='all'"/><div class="post-reward"><button class="tip-button reward-button"><span class="tip-button__text">打赏</span><div class="coin-wrapper"><div class="coin"><div class="coin__middle"></div><div class="coin__back"></div><div class="coin__front"></div></div></div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/weixin.jpg" target="_blank"><img class="post-qr-code-img" src="/img/weixin.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/img/taobao.jpg" target="_blank"><img class="post-qr-code-img" src="/img/taobao.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></button></div><script defer="defer" src="/"></script><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2019/03/27/MongoDB%E8%BF%9B%E9%98%B6/"><img class="prev-cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2017-07-20%2F4f06f9aa2ebcea6691a78537052e8e9f%2F00001.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530599&amp;t=32fb97bad7007bdc6c712ccadacd5721" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">MongoDB进阶</div></div></a></div><div class="next-post pull-right"><a href="/2019/03/26/koa%E4%B8%8Emongoose/"><img class="next-cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530644&amp;t=10679b5732c52e39eeb588040240a790" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Koa与mongoose</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2019/03/27/MongoDB进阶/" title="MongoDB进阶"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2017-07-20%2F4f06f9aa2ebcea6691a78537052e8e9f%2F00001.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530599&t=32fb97bad7007bdc6c712ccadacd5721" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-03-27</div><div class="title">MongoDB进阶</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/my.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">北城韩雨</div><div class="author-info__description">一个前端界的小学生</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">65</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">23</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">21</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/wazer1987"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="/wangzhengvslike@163.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content"><p>感谢访问本站，如喜欢请收藏。本站主要分享前端知识，立志成为资深前端工程师，但目前是一个前端界的小学生 若喜欢可以打赏请博主喝一杯冰阔落</p> <p>另外请大家多多支持淼哥的开源项目</p> <p>https://github.com/flipped-aurora/gin-vue-admin</p> <p>🌟🌟欢迎大家start 🌟🌟</p> <p>欢迎加入博主的前端技术交流群</p> <p style="background:rgba(255,255,255,1);margin:0"> <img src="/img/code.png"></img> </p></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B9%8B%E9%97%B4%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-text">数据库之间的区别</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="toc-text">基本操作</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E5%91%BD%E4%BB%A4"><span class="toc-text">基本命令</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%94%A8js%E6%96%87%E4%BB%B6%E6%9D%A5%E5%86%99MongoDB"><span class="toc-text">用js文件来写MongoDB</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%89%B9%E9%87%8F%E6%8F%92%E5%85%A5"><span class="toc-text">批量插入</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9"><span class="toc-text">修改</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%94%99%E8%AF%AF%E7%9A%84%E4%BF%AE%E6%94%B9"><span class="toc-text">错误的修改</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#set%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$set修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#unset%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$unset修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#inc%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$inc修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#multi"><span class="toc-text">multi</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#upset"><span class="toc-text">upset</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#push%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$push修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#ne%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$ne修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#addToSet%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$addToSet修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#each"><span class="toc-text">$each</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#pop"><span class="toc-text">$pop</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E7%9A%84%E5%AE%9A%E4%BD%8D%E4%BF%AE%E6%94%B9"><span class="toc-text">数组的定位修改</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BA%94%E7%AD%94%E5%BC%8F%E6%93%8D%E4%BD%9C"><span class="toc-text">应答式操作</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#findAndModify"><span class="toc-text">findAndModify</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2"><span class="toc-text">查询</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%A4%9A%E6%9D%A1%E4%BB%B6%E6%9F%A5%E8%AF%A2"><span class="toc-text">多条件查询</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#or-%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$or 修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#and%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$and修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#not-%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$not 修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%9A%84%E6%95%B0%E7%BB%84%E6%93%8D%E4%BD%9C"><span class="toc-text">数据的数组操作</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#all-%E6%95%B0%E7%BB%84%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$all 数组修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#in-%E6%95%B0%E7%BB%84%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$in 数组修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#size-%E6%95%B0%E7%BB%84%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$size 数组修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#slice%E6%95%B0%E7%BB%84%E4%BF%AE%E9%A5%B0%E7%AC%A6"><span class="toc-text">$slice数组修饰符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9C%A8js%E6%96%87%E4%BB%B6%E9%87%8C%E5%86%99%E6%9F%A5%E8%AF%A2"><span class="toc-text">在js文件里写查询</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/04/16/gin-vue-admin/" title="Gin-Vue-Admin"><img src="/img/gin-vue-admin.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Gin-Vue-Admin"/></a><div class="content"><a class="title" href="/2021/04/16/gin-vue-admin/" title="Gin-Vue-Admin">Gin-Vue-Admin</a><time datetime="2021-04-15T16:00:00.000Z" title="发表于 2021-04-16 00:00:00">2021-04-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/08/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%9310/" title="Vue源码开发-组件的渲染10"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530644&amp;t=10679b5732c52e39eeb588040240a790" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue源码开发-组件的渲染10"/></a><div class="content"><a class="title" href="/2021/01/08/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%9310/" title="Vue源码开发-组件的渲染10">Vue源码开发-组件的渲染10</a><time datetime="2021-01-07T16:00:00.000Z" title="发表于 2021-01-08 00:00:00">2021-01-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/07/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E5%90%88%E5%B9%B6%E7%AD%96%E7%95%A509/" title="Vue源码开发-组件合并策略09"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcz-video-photo.oss-cn-beijing.aliyuncs.com%2F20191017%2F4cfc341591d242327b67e9ceb6953612_00002.jpg&amp;refer=http%3A%2F%2Fcz-video-photo.oss-cn-beijing.aliyuncs.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530702&amp;t=80943e12d5239f63beafd6d1c540855f" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue源码开发-组件合并策略09"/></a><div class="content"><a class="title" href="/2021/01/07/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E5%90%88%E5%B9%B6%E7%AD%96%E7%95%A509/" title="Vue源码开发-组件合并策略09">Vue源码开发-组件合并策略09</a><time datetime="2021-01-06T16:00:00.000Z" title="发表于 2021-01-07 00:00:00">2021-01-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/06/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E6%95%B0%E7%BB%84%E7%9A%84%E4%BE%9D%E8%B5%96%E6%94%B6%E9%9B%8608/" title="Vue源码开发-数组的依赖收集08"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530644&amp;t=10679b5732c52e39eeb588040240a790" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue源码开发-数组的依赖收集08"/></a><div class="content"><a class="title" href="/2021/01/06/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E6%95%B0%E7%BB%84%E7%9A%84%E4%BE%9D%E8%B5%96%E6%94%B6%E9%9B%8608/" title="Vue源码开发-数组的依赖收集08">Vue源码开发-数组的依赖收集08</a><time datetime="2021-01-05T16:00:00.000Z" title="发表于 2021-01-06 00:00:00">2021-01-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/06/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E5%90%88%E5%B9%B607/" title="Vue源码开发-生命周期合并07"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2Faf41dabad727ba80c9ca8a2bfbd22a58%2F00004.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530659&amp;t=bbcfe1e86f393eecbb0722db1b92e475" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue源码开发-生命周期合并07"/></a><div class="content"><a class="title" href="/2021/01/06/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E5%90%88%E5%B9%B607/" title="Vue源码开发-生命周期合并07">Vue源码开发-生命周期合并07</a><time datetime="2021-01-05T16:00:00.000Z" title="发表于 2021-01-06 00:00:00">2021-01-06</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright"><span>&copy;2017 - 2021</span><svg style="width:2em; height:2em;position: relative;top: 10px;" aria-hidden="true"><use xlink:href="#icon-Butterfly"></use></svg><span>北城韩雨</span></div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><p><a style="margin-inline:5px" target="_blank" href="https://hexo.io/"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为Hexo"></a><a style="margin-inline:5px" target="_blank" href="https://butterfly.js.org/"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题采用butterfly"></a><a style="margin-inline:5px" target="_blank" href="https://www.jsdelivr.com/"><img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr" title="本站使用JsDelivr为静态资源提供CDN加速"></a></p></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><div class="js-pjax"></div><script defer src="/live2d-widget/autoload.js"></script><script src="/js/coin.js"></script><script async src="//at.alicdn.com/t/font_2700632_3rtvhzzpl3h.js"></script><script src="/js/liuxing.js" data-pjax></script><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '1s');
    arr[i].setAttribute('data-wow-delay', '0ms');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer src="https://cdn.jsdelivr.net/gh/graingert/wow@1.3.0/dist/wow.min.js"></script><script defer src="https://cdn.jsdelivr.net/npm/hexo-butterfly-wowjs/lib/wow_init.min.js"></script><script async src="//at.alicdn.com/t/font_2032782_8d5kxvn09md.js"></script><!-- hexo injector body_end end --></body></html>